#ifndef MDXSERVER_H
#define MDXSERVER_H

#include <QObject>
#include "server.h"
#include <QtSql/QtSql>
#include <QTimer>
#include "mlog.h"


#define VER "1.1"


#define ERR_EVENTOLDFAIL_ID 13
#define ERR_EVENTOLDFAIL "Error - This event has passed"
#define ERR_SQLDB_ID 12
#define ERR_SQLDB "Error - database isn't connected"
#define ERR_PROTOFAIL_ID 11
#define ERR_PROTOFAIL "Error - protocol version is incorrect"
#define ERR_TUIDFAIL_ID 10
#define ERR_TUIDFAIL "Error - tuid is incorrect"
#define ERR_BALANCEFAIL_ID 9
#define ERR_BALANCEFAIL "Error - balance is fail"
#define ERR_TARIFFEXIST_ID 8
#define ERR_TARIFFEXIST "Error - tariff exist"
#define ERR_EVENTEXIST_ID 7
#define ERR_EVENTEXIST "Error - event exist"
#define ERR_USEREXIST_ID 6
#define ERR_USEREXIST "Error - user exist"
#define ERR_SESSTESTERR_ID 5
#define ERR_SESSTESTERR "Error - sesstion fail"
#define ERR_SESSCLRERR_ID 4
#define ERR_SESSCLRERR "Error - clearing sessions"
#define ERR_SQLERR_ID 3
#define ERR_SQLERR "interal server sql error"
#define ERR_PARAMSCOUNT_ID 1
#define ERR_PARAMSCOUNT "parameters count is error"
#define ERR_LOGON_ID 2
#define ERR_LOGON "login or password is incorrect"


class MDxserver : public QObject
{
    Q_OBJECT
    xmlrpc::Server * server;
    QString protoV;
    int port;
    int session_ttl;
    QSqlDatabase db;
    QTimer * dbtimer;
    bool isDbtimerTest;
    bool isReticketEvent;
    QString sqlsafe(const QString & str);
    bool clearOldSessions();
    bool testSesstion(const QString & uname, const QString & uhash);
public:
    explicit MDxserver(QObject *parent = 0);
    void setPort(int);
    void setBase(const QString & addr, const QString & user, const QString & pass, const QString & dbname, int port=3306);
    void setSessionTtl(int sec);
    void setReticketEvent(bool value);
    void start( int pingMins);

    
signals:
    void sigLog(const QString module, int loglevel, const QString logtext );
    
public slots:
private slots:
    void slotProcessRequest( int id, QString methodName, QList<xmlrpc::Variant> parameters);
    void slotTimerTik();
    
};

#endif // MDXSERVER_H
